const getCookies = require('../until/getCookies')
const url = require('url')
const {ADMIN_UID} = require('../config/config.data')

// 登录状态校验

module.exports = (req,res,next) =>{
    
    let uidResult = getCookies(req.get('cookie'),'adminuid')
    let isLogined = ADMIN_UID.find(item=>item.adminuid === uidResult)
    
    if(!isLogined ){
        res.send({code:0,msg:"没有登录，请登录后访问"})
        return
    }  
  
    // 判断用户是否登录
    if(url.parse(req.url).pathname ==='/isloginin'){
        res.send({code:1,msg:"登录成功"})
        return
    }

    next()
}